
package entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import java.text.DateFormat;
import java.text.SimpleDateFormat;



/**
 *
 * @author Chenhui
 */
@Entity
public class EntryHistoryEntity implements Serializable {
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    private String dateEntry;
    private String actor;
    private String info;
    
    @ManyToOne(cascade={CascadeType.PERSIST})
    private PortfolioEntryEntity portfolioEntry;
    
    public EntryHistoryEntity(){}
    
    public void create(String actor, String info){
        this.setDateEntry();
        this.setActor(actor);
        this.setInfo(info);
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    
    public String getDateEntry() {
        return dateEntry;
    }

    public void setDateEntry() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        this.dateEntry = dateFormat.format(new Date());
    }


    /**
     * @return the actor
     */
    public String getActor() {
        return actor;
    }

    /**
     * @param actor the actor to set
     */
    public void setActor(String actor) {
        this.actor = actor;
    }

    /**
     * @return the info
     */
    public String getInfo() {
        return info;
    }

    /**
     * @param info the info to set
     */
    public void setInfo(String info) {
        this.info = info;
    }

    /**
     * @return the portfolioEntry
     */
    public PortfolioEntryEntity getPortfolioEntry() {
        return portfolioEntry;
    }

    /**
     * @param portfolioEntry the portfolioEntry to set
     */
    public void setPortfolioEntry(PortfolioEntryEntity portfolioEntry) {
        this.portfolioEntry = portfolioEntry;
    }
}
